from EmpVoting.Stat import BaseStatFromFieldCollection

class NetworkStatFromEdgeField(BaseStatFromFieldCollection):

    def __init__(self, fieldName, statOp):
        '''
        Constructor
        
        Supported stat operations are: "mean", "std", "distribution", "max", "min", "list", "flat"
        '''
        self.FieldName = fieldName
        self.StatOp = statOp
        
    def Apply(self, network):
        valList = []
        edgeList = network.graph.edges(data=True)
        for edge in edgeList:
            edgeData = edge[2]
            valList.append(edgeData[self.FieldName])
            
        statResult = self._CalcStatFromList(valList, self.StatOp)
        network.__dict__["edge_" + self.FieldName + "_" + self.StatOp] = statResult